#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/shm.h>

int main()
{
	key_t key = 0;
	int shmid = 0;
	int ret = 0;

	key = ftok("/home/hua/yanfa15",1);
	if(key == -1)
	{
		perror("ftok");
		exit(-1);
	}

	shmid = shmget(key,1024,IPC_CREAT|0600);
	if(shmid == -1)
	{
		perror("shmget");
		exit(-1);
	}


	char *str = NULL;

	str = shmat(shmid,NULL,0);
	if(str == (void *)-1)
	{
		perror("shmat");
		exit(-1);
	}
	
	char dest[100] = {0};
	strcpy(dest,str);

	printf("dest is %s\n",dest);

	ret = shmdt(str);
	if(ret == -1)
	{
		perror("shmdt");
		exit(-1);
	}


	return 0;
}
